package sk.hackcraft.util.simulation;

import java.util.logging.Level;
import java.util.logging.Logger;

public class SystemEvent extends Event
{
	private static final Logger logger = Logger.getLogger(SystemEvent.class.getName());
	
	public SystemEvent(double time)
	{
		super(time);
	}

	@Override
	public void execute()
	{
		try
		{
			SimulationController controller = getReplication().getController();
			
			Thread.sleep(995 / controller.getSimulationSpeed());
			
			if(controller.isCollecting())
			{
				getReplication().planEvent(new SystemEvent(getTime()+0.95));
				controller.setSystemEventExists(true);
			}
			else
			{
				controller.setSystemEventExists(false);
			}
		}
		catch (InterruptedException ex)
		{
			logger.log(Level.SEVERE, null, ex);
		}
	}
}
